#include<cstdio>
#include<algorithm>
using namespace std;
const int N = 100005;
int stack[N], cnt = -1;

void push(int x){
	stack[++cnt] = x;
}
void pop(){
	cnt--;
}
int top(){
	return stack[cnt];
}

int main(){
	int t = 0, n, x, op;
	scanf("%d", &t);
	while(t--){
		cnt = -1;
		scanf("%d", &n);
		for(int i=0;i<n;i++){
			scanf("%d", &op);
			switch (op) {
				case 1:
					scanf("%d", &x);
					push(x);
					break;
				case 2:
					if(cnt==-1){
						printf("empty\n");
					}else{
						pop();
					}
					break;
				case 3:
					if(cnt==-1){
						printf("empty\n");
					}else{
						printf("%d\n", top());
					}
					break;
				default:
					//TODO
					break;
			}
		}
		sort(stack, stack + cnt + 1);
		for(int i=0;i<=cnt;i++){
			printf("%d ", stack[i]);
		}
		printf("\n");
	}
	return 0;
}
